/*
 * @Author: 肖思汗 
 * @Date: 2025-08-22 23:33:36 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2025-09-24 20:55:57
 */
import react from '@vitejs/plugin-react'
import { fileURLToPath, URL } from 'url';
import dayjs from "dayjs";
import type { UserConfigExport, ConfigEnv } from 'vite';

// https://vitejs.dev/config/
export default ({ mode }: ConfigEnv): UserConfigExport => {

    const nowDate = dayjs().format("YYYY-MM-DD HH:mm:ss");

    return ({

        base: "./",
        // 全局替换
        define: {
            "process.env.NODE_ENV": `'${mode}'`,
            "process.env.BUILD_TIME": `'${nowDate}'`,
        },
        build: {
            outDir: 'dist',
            assetsInlineLimit: 1024 * 0, // 10k 以下的图片转成 base64
            minify: 'terser',
            terserOptions: {
                compress: {
                    drop_console: false,
                    drop_debugger: true,
                }
            },
            chunkSizeWarningLimit: 1024 * 100,
            rollupOptions: {
                input: {
                    "index": fileURLToPath(new URL('./index.html', import.meta.url))
                }
            }
        },
        plugins: [
            react() as unknown as import('vite').Plugin
        ],
        resolve: {
            alias: {
                "@": fileURLToPath(new URL('./', import.meta.url)),
            }
        },
        css: {
            preprocessorOptions: {
                less: {
                    javascriptEnabled: true,// 支持内联 javascript
                },
            }
        }
    })

}
